//
//  ZYXNSThread2ViewController.m
//  MultiThreading
//  线程状态
//

#import "ZYXNSThread2ViewController.h"

@interface ZYXNSThread2ViewController ()

@property (nonatomic, strong) NSThread *thread;

@end

@implementation ZYXNSThread2ViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.thread = [[NSThread alloc] initWithTarget:self selector:@selector(test) object:nil];
    self.thread.name = @"线程A";
    
}

- (void)test
{
    NSLog(@"test - 开始 - %@", [NSThread currentThread].name);
    
//    [NSThread sleepForTimeInterval:5]; // 子线程 阻塞状态 5秒
    
    NSDate *date = [NSDate dateWithTimeIntervalSinceNow:5.0];
    [NSThread sleepUntilDate:date];
    
    for (int i = 0; i<10; i++) {
        NSLog(@"test - %d - %@", i, [NSThread currentThread].name);
        
        if (i == 5) {
            //[NSThread exit];  // 子线程 死亡状态
            return;
        }
    }
    
    NSLog(@"test - 结束 - %@", [NSThread currentThread].name);
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // 开启线程
    [self.thread start];
}


@end
